package com.zangchat.controller;

import com.common.core.domain.AjaxResult;
import com.zangchat.domain.ChatUsers;
import com.zangchat.domain.ChatUsersDTO;
import com.zangchat.service.NearBySearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/zangchat/nearBySearch")
public class NearBySearchController {

    @Autowired
    private NearBySearchService nearBySearchService;

    /**
     * 将经纬度储存到缓存
     * @param users
     * @return
     */
    @RequestMapping("/save")
    public AjaxResult save(@ModelAttribute("userId") Long userId,
                           @ModelAttribute("longitude") double longitude,
                           @ModelAttribute("latitude") double latitude){
        return nearBySearchService.save(userId,longitude,latitude);
    }

    /**
     * 根据当前位置获取附近指定范围内的用户
     * @param distance 指定范围 单位km ，可根据{@link org.springframework.data.geo.Metrics} 进行设置
     * @param userLng 用户经度
     * @param userLat 用户纬度
     * @return
     */
    public AjaxResult nearBySearch(@ModelAttribute("distance") double distance,
                                   @ModelAttribute("userLng") double userLng,
                                   @ModelAttribute("userLat") double userLat){
        return nearBySearchService.nearBySearch(distance,userLng,userLat);
    }



}
